Skip to content

fix(cloudflare): Try/catch on non-configurable prototypes - #23132

Merged
JPeer264 merged 1 commit into
developfrom
jp/missing-comment
Aug 7, 2026
Merged

fix(cloudflare): Try/catch on non-configurable prototypes#23132
JPeer264 merged 1 commit into
developfrom
jp/missing-comment

Conversation

@JPeer264

@JPeer264 JPeer264 commented Aug 7, 2026

Copy link
Copy Markdown
Member

Missed a comment here: #23057 (comment)

@JPeer264
JPeer264 requested a review from chargome August 7, 2026 07:42
@JPeer264 JPeer264 self-assigned this Aug 7, 2026
@JPeer264
JPeer264 requested a review from a team as a code owner August 7, 2026 07:42
@JPeer264
JPeer264 requested review from isaacs and mydea and removed request for a team August 7, 2026 07:42
Comment on lines +331 to 337
try {
Object.defineProperty(prototype, methodName, { ...descriptor, value: wrapped });
} catch {}

// Only the wrapper is marked, not the original method: `wrapMethodWithSentry` resolves
// through the same global map and must not resolve the original to this wrapper,
// which would recurse.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The code repeatedly tries to instrument non-configurable methods on each new class instance because it doesn't mark them as "failed to wrap" after the first attempt.
Severity: LOW

Suggested Fix

To prevent redundant work, the original method should be marked as having had an instrumentation attempt, even if it fails. This could be achieved by marking the original descriptor.value within the catch block after Object.defineProperty throws, preventing getRpcMethodDescriptor from re-selecting it for wrapping on subsequent constructions.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/cloudflare/src/durableobject.ts#L331-L337

Potential issue: When a class has a non-configurable method, the instrumentation logic
attempts to wrap it using `Object.defineProperty`. This fails as expected, but the
original method is not marked to prevent future wrapping attempts. Consequently, for
every new instance of the class, the system re-attempts the same failed wrapping
operation. This results in minor performance overhead due to the creation of a new
closure and a doomed `defineProperty` call on each construction. The application's
functionality is not affected, but it introduces redundant work.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 30.15 kB - -
@sentry/browser - with treeshaking flags 28.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.66 kB - -
@sentry/browser (incl. Tracing) 47.56 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.57 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.31 kB - -
@sentry/browser (incl. Tracing, Replay) 86.93 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.36 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.66 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 104.29 kB - -
@sentry/browser (incl. Feedback) 47.48 kB - -
@sentry/browser (incl. sendFeedback) 34.98 kB - -
@sentry/browser (incl. FeedbackAsync) 40.13 kB - -
@sentry/browser (incl. Metrics) 31.22 kB - -
@sentry/browser (incl. Logs) 31.44 kB - -
@sentry/browser (incl. Metrics & Logs) 32.13 kB - -
@sentry/react 31.95 kB - -
@sentry/react (incl. Tracing) 49.81 kB - -
@sentry/vue 35.25 kB - -
@sentry/vue (incl. Tracing) 49.57 kB - -
@sentry/svelte 30.17 kB - -
CDN Bundle 32.16 kB - -
CDN Bundle (incl. Tracing) 47.83 kB - -
CDN Bundle (incl. Logs, Metrics) 33.7 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.21 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.03 kB - -
CDN Bundle (incl. Tracing, Replay) 85.47 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.79 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.29 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.61 kB - -
CDN Bundle - uncompressed 95.33 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.84 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.96 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.82 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.66 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.09 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.06 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.8 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.75 kB - -
@sentry/nextjs (client) 52.39 kB - -
@sentry/sveltekit (client) 48.01 kB - -
@sentry/core/server 65.58 kB - -
@sentry/core/browser 51.82 kB - -
@sentry/node 119.28 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 83.3 kB +0.01% +1 B 🔺
@sentry/aws-serverless 92.61 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 214.17 kB +0.01% +11 B 🔺
@sentry/cloudflare (withSentry) 528.87 kB +0.01% +38 B 🔺

View base workflow run

@JPeer264
JPeer264 merged commit 574c875 into develop Aug 7, 2026
149 of 151 checks passed
@JPeer264
JPeer264 deleted the jp/missing-comment branch August 7, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants